//
//  GDListViewTableViewCell.m
//  Gunterapple
//
//  Created by 热带雨林 on 2021/1/30.
//  Copyright © 2021 热带雨林. All rights reserved.
//

#import "GDListViewTableViewCell.h"
#import "viewModel.h"
@interface GDListViewTableViewCell ()
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *informLabel;
@property (nonatomic, strong) UIImageView *inforImageView;
@property (nonatomic, strong) UIView *backView;
@end

@implementation GDListViewTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setUpUI];
    }
    return self;
}
- (void)setUpUI{
    self.contentView.backgroundColor = [UIColor blackColor];
    
    self.backView = [[UIView alloc]initWithFrame:CGRectZero];
    self.backView.backgroundColor = [UIColor whiteColor];
    self.backView.hidden = YES;
    self.backView.layer.cornerRadius =10.0f;
    self.backView.layer.masksToBounds = YES;
    [self.contentView addSubview:self.backView];
    
    UIEdgeInsets padding = UIEdgeInsetsMake(5, 5, 5, 5);
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self.contentView).insets(padding);
    }];
    
    self.inforImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
    [self.contentView addSubview:self.inforImageView];
    self.inforImageView.image = [UIImage imageNamed:@"icon3"];
    self.inforImageView.layer.cornerRadius = 5.0f;
    self.inforImageView.layer.masksToBounds = YES;
    [self.inforImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(15);
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.centerY.equalTo(self.contentView);
    }];
    self.nameLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.nameLabel];
    self.nameLabel.text = @"插入多条数据到数据库中";
    self.nameLabel.font = [UIFont systemFontOfSize:12];
    self.nameLabel.textColor = [UIColor whiteColor];
    self.nameLabel.numberOfLines = 0;
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.inforImageView.mas_right).offset(10);
        make.top.equalTo(self.contentView).offset(10);
        //宽度为 100 - 110 之间
        make.width.mas_lessThanOrEqualTo(109);
//        make.width.mas_greaterThanOrEqualTo(110);
    }];
    self.informLabel = [[UILabel alloc]init];
    [self.contentView addSubview:self.informLabel];
    self.informLabel.text = @"FMDB功能按钮";
    self.informLabel.font = [UIFont systemFontOfSize:8];
    self.informLabel.textColor = [UIColor whiteColor];
    self.informLabel.numberOfLines = 0;
    [self.informLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(3);
        make.width.mas_lessThanOrEqualTo(109);
    }];
}

- (void)setModel:(viewModel *)model{
    _model = model;
    self.nameLabel.text = model.name;
    self.informLabel.text = model.descName;
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated{
    [super setSelected:selected animated:animated];
    [self changeSelectionColorForSelectedOrHighLightedState:selected];
}

- (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated{
    [super setHighlighted:highlighted animated:animated];
    [self changeSelectionColorForSelectedOrHighLightedState:highlighted];
}
- (void)changeSelectionColorForSelectedOrHighLightedState:(BOOL)status{
    if(status){
        self.backView.hidden = NO;
        self.nameLabel.textColor = [UIColor blackColor];
        self.informLabel.textColor = [UIColor blackColor];
    }else{
        self.backView.hidden = YES;
        self.nameLabel.textColor = [UIColor whiteColor];
        self.informLabel.textColor = [UIColor whiteColor];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
}

@end
